#ifndef CHAP9_H_
#define CHAP9_H_

/*usb request define*/
#define CLEAR_FEATURE 0x1
#define GET_CONFIGURATION 0x8
#define GET_DESCRIPTOR	0x6
#define GET_INTERFACE 0xa
#define GET_STATUS	0x0
#define SET_ADDRESS 0x5
#define SET_CONFIGURATION 0x9
#define SET_DESCRIPTOR	0x7
#define SET_FEATURE	0x3
#define SET_INTERFACE 0xb
#define SYNCH_FRAME 0xc

/* USB Class Request */
#define BULK_ONLY_MASS_STORAGE_RESET 1
#define GET_MAX_LUN 2

// Values for bmAttributes field of an
// endpoint descriptor
//

#define EP1_PACKET_SIZE 64
#define EP2_PACKET_SIZE 64

/**/
// FSM status define
#define USB_CONTROL_IDLE 0
#define USB_CONTROL_SETUP 1
#define USB_CONTROL_HANDLE 2
#define USB_CONTROL_HANDSHAKE 3
#define USB_CONTROL_DATA_IN 4
#define USB_CONTROL_DATA_OUT 5
#define USB_CONTROL_NONDATA 6
#define USB_CONTROL_SET 7


#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
/**/
typedef struct usbDeviceRequestS{
char		bmRequestType;
char		bRequest;
short	wValue;
short	wIndex;
short	wLength;} usbDeviceRequest;

typedef struct usbEnuFsmS{
char *rxBuf;
char *txBuf;
char fsmStatus;
char usbRequest;
char usbClassRequest;
char ep0Status;

} usbEnuFsm;

typedef struct _USB_DEVICE_DESCRIPTOR {
    char bLength;
	char bDescriptorType;
    char bcdUSB_L;
    char bcdUSB_H;
    char bDeviceClass;
    char bDeviceSubClass;
    char bDeviceProtocol;
    char bMaxPacketSize0;
    char idVendor_L;
    char idVendor_H; 
    char idProduct_L;       
    char idProduct_H;
    char bcdDevice_L;
    char bcdDevice_H;
    
    char iManufacturer;
    char iProduct;
    char iSerialNumber;
    char bNumConfigurations;
}USB_DEVICE_DESCRIPTOR;

typedef struct _USB_CONFIGURE_DESCRIPTOR{
	char bLength;
	char bDescriptorType;
	short wTotalLength;
	char	BNumInterfaces;
	char bConfigurationValue;
	char iCongfiguration;
	char bmAttribute;
	char MaxPower;
} USB_CONFIGURE_DESCRIPTOR;

typedef struct _USB_INTERFACE_DESCRIPTOR{
	char bLength;
	char bDescriptorType;
	char bInterfaceNumber;
	char bAlternateSetting;
	char bNumberEndpoints;
	char bInterfaceClass;
	char bInterfaceSubClass;
	char bInterfaceProtocol;
	char iInterface;
} USB_INTERFACE_DESCRIPTOR;

typedef struct _USB_ENDPOINT_DESCRIPTOR{
	char bLength;
	char bDescriptorType;
	char bEndpointAddress;
	char bmAttributes;
	short wMaxPacketSize;
	char bInterval;
} USB_ENDPOINT_DESCRIPTOR;







//
// Standard USB HUB definitions
//
// See Chapter 11
//

/* function definition*/
int analyseUsbRequest(char* request);
#endif /*CHAP9_H_*/
